﻿using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using YogaStudio.Data.Domain;
using YogaStudio.Data.Migrations;

namespace YogaStudio.Data
{
    public class YogaStudioEntities : DbContext, IYogaStudioEntities
    {
        public IDbSet<Product> Products { get; set; }
        public IDbSet<Category> Categories { get; set; }
        public DbSet<Semester> Semesters { get; set; }
        public DbSet<Room> Rooms { get; set; }
        public DbSet<Schedule> Schedules { get; set; }
        public DbSet<Section> Sections { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<UserRole> UserRoles { get; set; }
        public DbSet<Faculty> Faculties { get; set; }
        public DbSet<Customer> Customers { get; set; }
        public IDbSet<WaiverRequest> WaiverRequests { get; set; }
        public IDbSet<ShoppingCart> ShoppingCarts { get; set; }
        public IDbSet<OrderItem> OrderItems { get; set; }
        public IDbSet<Course> Courses { get; set; }
        public DbSet<Shipping> Shippings { get; set; }
        public DbSet<ShippingStatus> ShippingStatus { get; set; }
        public DbSet<Order> Orders { get; set; }
        public DbSet<Transcript> Transcripts  { get; set; }
        public DbSet<Waitinglist> WaitingLists { get; set; }
        public DbSet<CoursePaymentDetail> CoursePaymentDetails { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

            modelBuilder.Entity<Customer>().HasMany(c => c.Sections)
                .WithMany(s => s.Customers)
                .Map(k => k.MapLeftKey("CustomerId").MapRightKey("SectionId").ToTable("Enrollment"));
        }
        static YogaStudioEntities()
        {
            
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<YogaStudioEntities, Configuration>());
        }

    }
}
